﻿CREATE PROCEDURE [dbo].[yaf_registry_list](
                @Name    NVARCHAR(50)  = NULL,
                @BoardID INT  = NULL)
AS
    BEGIN
        IF @BoardID IS NULL
        BEGIN
            IF @Name IS NULL 
                OR @Name = ''
            BEGIN
                SELECT *
                FROM   yaf_Registry
                WHERE  BoardID IS NULL
            END
            ELSE
            BEGIN
                SELECT *
                FROM   yaf_Registry
                WHERE  Lower(Name) = Lower(@Name)
                AND BoardID IS NULL
            END
        END
        ELSE
        BEGIN
            IF @Name IS NULL 
                OR @Name = ''
            BEGIN
                SELECT *
                FROM   yaf_Registry
                WHERE  BoardID = @BoardID
            END
            ELSE
            BEGIN
                SELECT *
                FROM   yaf_Registry
                WHERE  Lower(Name) = Lower(@Name)
                AND BoardID = @BoardID
            END
        END
    END


